package org.lanqiao.inteceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.orm.EleManager;
import org.lanqiao.orm.EleOpeartor;
import org.lanqiao.orm.EleUser;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class UserLoginInteceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		// 对于是login的请求开后门
		// 注意：这里由于是使用url进行识别，所以在编程中需要将登陆的请求url名和
		if (request.getRequestURI().contains("/user/login.action")) {
			return true;
		}
		/*
		 * 非登录请求： 获取当前请求sesion中是否缓存了用户登录信息 如果缓存了用户登录信息，则进行放行， 否则，准会登录页面，进行拦截
		 */
		// 管理员拦截器
		String islogin = (String) request.getSession().getAttribute("islogin");
		if (islogin!=null&&islogin.equals("success")) {
			return true;
		} else {
			response.sendRedirect("../login.jsp");
			return false;
		}
	}

	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}

}
